﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using TrainingsApp.Model;
using WisDragon.Framework.Data.DataAccess;
using TrainingsApp.Helper;

namespace TrainingsApp.DAL.Imp.Auto {
    public class TS_SystemInfoSetting_DAL {
        public static List<TS_SystemInfo_Entity> GetConfig(string name) {
            //

            try {
                DataCommand cmd = DataCommandManager.GetDataCommand("TS_SystenInfo_View");
                cmd.SetParameterValue("@ConfigName", name);

                return cmd.ExecuteEntityList<TS_SystemInfo_Entity>();
            }
            catch (Exception ex) {
                ExceptionHelper.ProcessException(ex);
            }
            return new List<TS_SystemInfo_Entity>(0);
        }

        public static void Update(TS_SystemInfo_Entity entity) {
            if (entity != null) {
                try {
                    DataCommand cmd = null;
                    if (entity.Idx > 0) {
                        cmd = DataCommandManager.GetDataCommand("TS_SystenInfo_Update");
                        cmd.SetParameterValue("@Idx", entity.Idx);
                    }
                    else {
                        cmd = DataCommandManager.GetDataCommand("TS_SystenInfo_Add");

                    }
                    cmd.SetParameterValue("@ConfigValue", entity.ConfigValue);
                    cmd.SetParameterValue("@ConfigName", entity.ConfigName);
                    cmd.ExecuteNonQuery();
                }
                catch (Exception ex) {
                    ExceptionHelper.ProcessException(ex);

                }
            }
        }

    }
}
